package com.cxz.kotlin.baselibs.widget;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.cxz.kotlin.baselibs.R;
import com.cxz.kotlin.baselibs.base.MyBaseDialog;

import java.lang.ref.WeakReference;


/**
 * Loading 弹窗
 *
 * @author gyc
 * @date 2018/7/30
 */
public class CustomLoadingDialog extends MyBaseDialog {

    private TextView loadingText;

    public CustomLoadingDialog(Context context) {
        super(context);
    }

    public CustomLoadingDialog(WeakReference<Context> context) {
        super(context.get());
    }

    @Override
    protected int getContentId() {
        return R.layout.dialog_loading_layout;
    }

    @Override
    protected void init() {
        loadingText = (TextView) findViewById(R.id.tv_loading_info);
        getWindow().setDimAmount(0f);
    }

    /**
     * 设置提示文字By string
     *
     * @param msg
     * @return
     */
    public CustomLoadingDialog setMessage(String msg) {
        if (!TextUtils.isEmpty(msg)) {
            loadingText.setText(msg);
            setLoadingTextVisibility(true);
        } else {
            loadingText.setText("");
            setLoadingTextVisibility(false);
        }
        return this;
    }

    /**
     * 设置提示文字By id
     */
    public CustomLoadingDialog setMessage(int res) {
        String msg = getContext().getResources().getString(res);
        return setMessage(msg);
    }

    /**
     * 设置Title是否可见
     */

    public void setLoadingTextVisibility(boolean isVisible) {
        loadingText.setVisibility(isVisible ? View.VISIBLE : View.GONE);
    }
}
